<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>179给数组扩展sum和max实例方法</title>
</head>

<body>
  <h1>179给数组扩展sum和max实例方法</h1>
  <script>
    // 1 通过原型对象给Array扩展sum和max实例方法。
    Array.prototype.sum = function () {
      return this.reduce((a, c) => {
        return a + c
      }, 0)
    }
    console.log([1, 2, 3].sum())

    Array.prototype.max = function () {
      return Math.max(...this)
    }
    console.log([1, 2, 3].max())
  </script>
</body>

</html>